package com.tt.job.zookeeper;

import com.tt.job.register.PathConst;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "job.zk")
public class ZookeeperSettings {

    private String host = "localhost:2181";
    private String leaderPath = PathConst.LEADER;
    private String root = PathConst.ROOT;

    /**
     * 注册中心地址
     *
     * @return
     */
    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    /**
     * zookeeper中leader路径
     *
     * @return
     */
    public String getLeaderPath() {
        return leaderPath;
    }

    public void setLeaderPath(String leaderPath) {
        leaderPath = leaderPath.startsWith("/") ? leaderPath : "/" + leaderPath;
        this.leaderPath = leaderPath;
    }

    /**
     * zookeeper中使用的根节点路径
     *
     * @return
     */
    public String getRoot() {
        return root;
    }

    public void setRoot(String root) {
        //保证节点是以/开始
        root = root.startsWith("/") ? root : "/" + root;
        this.root = root;
    }
}
